/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * NewJFrame.java
 *
 * Created on 3 mai 2011, 21:30:01
 */

package ihm_clarifiee.test;

import ihm_clarifiee.Control.CBacklog;
import ihm_clarifiee.Control.CProjet;
import ihm_clarifiee.Control.CRelease;
import ihm_clarifiee.Control.CUsine;
import ihm_clarifiee.Presentation.PBacklog;
import ihm_clarifiee.Presentation.PListeReleases;
import ihm_clarifiee.Presentation.PProjet;
import ihm_clarifiee.application.Projet;

import java.io.File;

import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

/**
 *
 * @author Arthur
 */
public class Accueil extends javax.swing.JFrame {

 
    public Accueil() {
        initComponents();
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        }

   private void initComponents() {

	   bt_new = new javax.swing.JButton();
       bt_ouvrir = new javax.swing.JButton();
       jLabel1 = new javax.swing.JLabel();

       setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
       setTitle("Accueil");
       setResizable(false);

       bt_new.setText("Nouveau projet");

       bt_ouvrir.setText("Ouvrir projet");

       jLabel1.setText("GESTIONNAIRE SCRUM");

       javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
       getContentPane().setLayout(layout);
       layout.setHorizontalGroup(
           layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
           .addGroup(layout.createSequentialGroup()
               .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                   .addGroup(layout.createSequentialGroup()
                       .addContainerGap()
                       .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                           .addComponent(bt_ouvrir, javax.swing.GroupLayout.DEFAULT_SIZE, 162, Short.MAX_VALUE)
                           .addComponent(bt_new, javax.swing.GroupLayout.DEFAULT_SIZE, 162, Short.MAX_VALUE)))
                   .addGroup(layout.createSequentialGroup()
                       .addGap(35, 35, 35)
                       .addComponent(jLabel1)))
               .addContainerGap())
       );
       layout.setVerticalGroup(
           layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
           .addGroup(layout.createSequentialGroup()
               .addGap(16, 16, 16)
               .addComponent(jLabel1)
               .addGap(18, 18, 18)
               .addComponent(bt_new)
               .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
               .addComponent(bt_ouvrir)
               .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
       );
        
        bt_ouvrir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_ouvrirActionPerformed(evt);
            }
        });
        
        bt_new.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_newActionPerformed(evt);
            }
        });
        
        pack();
    }// </editor-fold>

    private void bt_ouvrirActionPerformed(java.awt.event.ActionEvent evt) {
        javax.swing.JFileChooser jfc = new javax.swing.JFileChooser();
        jfc.setDialogType(JFileChooser.OPEN_DIALOG);
        int returnVal = jfc.showOpenDialog(this);
        jfc.setVisible(true);
        
        if (returnVal == JFileChooser.APPROVE_OPTION) {
        	File file = jfc.getSelectedFile();
        	try{    		
        		
        		CProjet cProj = Projet.restoreFromXML(file.getPath(),file.getParent());
        		PProjet pProj = cProj.getPresentation();
        		
//        		TODO
        		CBacklog cb = cProj.getCBacklog(); 	
        		PBacklog pb = cb.getPresentation();     		
        		
        		cProj.setBacklog(cb);
//        		set la présentation du bklg au projet
        		cProj.getPresentation().setPBacklog(pb);
        		
        		System.out.println("Accueil, taille liste des histoires : "+cb.getListeHistoires().size());
        		
//        		Fenetre de presentation du projet
        		pProj.setVisible(true);
        		pProj.setSize(1500,750);
        		
//        		Restauration des champs
//        		Release
        		pProj.updateListeReleases();
        		pProj.viewRelease();
        		
//        		backlog
        		pb.updateAffichage();
        		pProj.viewBacklog();
        		
        		pProj.update();
        		
    	    	this.dispose();
        	}
        	catch(Exception e){
        		JOptionPane.showMessageDialog(this, "Ce fichier ne permet pas de restaurer un projet.");
        	}
        }
    }
    
    private void bt_newActionPerformed(java.awt.event.ActionEvent evt) {
        javax.swing.JFrame jf = new javax.swing.JFrame();
        jf.setResizable(false);
        jf.setTitle("Nouveau projet");
    	newProjet np = new newProjet(jf, this);
        np.setVisible(true);
        jf.setVisible(true);
        jf.add(np);
        jf.setDefaultCloseOperation(javax.swing.JFrame.DISPOSE_ON_CLOSE);
        jf.setSize(1000,500);
    }
    
    
    private void bt_newutilisateurActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }

    private void bt_listeutilisateursActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Accueil().setVisible(true);
            }
        });*/
        
        new Accueil().setVisible(true);
    }
    // Variables declaration - do not modify
    private javax.swing.JButton bt_listeutilisateurs;
    private javax.swing.JButton bt_new;
    private javax.swing.JButton bt_newutilisateur;
    private javax.swing.JButton bt_ouvrir;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JLabel lb_intro;
    private javax.swing.JLabel lb_titre;
    // End of variables declaration
}
